<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="btn">test</button>
  <script>
    /* 
    同步回调
    异步回调
    */


    // 同步回调
    /* [1, 2, 3].forEach(item => {
      console.log(item)
    })
    console.log('forEach()之后') */

    
    const p = new Promise((resolve, reject) => { // 执行器  ==> 同步执行的
      console.log('excutor')
      // 启动异步任务

      // 如果成功了, 将promise变为成功(调用resolve(value))

      // 如果失败了, 将promise变为失败(调用reject(reason))
    })

    console.log('new Promise()之后');


    // 异步回调
    setTimeout(() => { 
      console.log('执行timout回调')
    }, 0)
    console.log('setTimeout()之后')

    Promise.resolve(1).then(() => {// 异步回调
      console.log('promise成功的回调')
    })
    
    console.log('.then之后')
  </script>

  <script>
   function fn1() {
     setTimeout(() => {  // 将回调函数和时间交给定时器管理模块
       console.log('timeout callback')
     }, 1000);
   }

   function fn2() { // 将回调交给DOM事件管理模块 
     document.getElementById('btn').onclick = function () {
       console.log('dom event callback')
     }
   }

   function fn3() { // 将回调交给ajax管理模块
     $.get('../test.json', (data) => {
        console.log('ajax callback')
     })
   }

   function fn4() {
     console.log('同步任务')
     for (let index = 0; index < 100000; index++) {
       
     }
   }

   fn1()
   fn2()
   fn3()
   fn4()

    
  </script>
</body>
</html>